//
//  ZHMineHeadView.m
//  LoveFreshBee
//
//  Created by brice Mac on 2016/10/15.
//  Copyright © 2016年 王忠迪. All rights reserved.
//
#define kHeadViewSize self.bounds.size

#import "ZHMineHeadView.h"
#import "ZHMineSetViewController.h"

@interface ZHMineHeadView ()

@end

@implementation ZHMineHeadView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //设置UI
        [self setupMineHeadViewUI];
        
    }
    return self;
}

- (void)setupMineHeadViewUI {
    
    self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"v2_my_avatar_bg"]];
    
    //实例化子控件
    //1.实例化iconView
    UIView *iconView = [[UIView alloc]initWithFrame:CGRectMake(0.5*(kHeadViewSize.width - kHeadViewSize.height), kHeadViewSize.height*0.2, kHeadViewSize.height, kHeadViewSize.height*0.8)];
    //计算iconView的宽
    CGFloat iconWidth = iconView.bounds.size.width;
    //计算iconImageView的宽和高
    CGFloat imgWH = iconWidth * 0.5;
    //设置iconImageView
    UIImageView *iconImgV = [[UIImageView alloc]initWithFrame:CGRectMake(0.5*(iconWidth - imgWH), 0, imgWH, imgWH)];
    iconImgV.image = [UIImage imageNamed:@"v2_my_avatar"];
    [iconView addSubview:iconImgV];
    //设置phoneLabel
    UILabel *phoneLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, imgWH+5, 2*imgWH, 30)];
    phoneLabel.text = @"18828885888";
    phoneLabel.textColor = [UIColor blackColor];
    phoneLabel.textAlignment = NSTextAlignmentCenter;
    [iconView addSubview:phoneLabel];
    //把iconView 添加到整个 HeadView 中
    [self addSubview:iconView];
    
    //2.实例化setButton
    UIButton *setButton = [[UIButton alloc] initWithFrame:CGRectMake(kHeadViewSize.width-50, 10, 50, 50)];
    [setButton setImage:[UIImage imageNamed:@"v2_my_settings_icon"] forState:UIControlStateNormal];
    
    [setButton addTarget:self action:@selector(setButtonDidClick) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:setButton];
    
}

//设置按钮点击事件
- (void)setButtonDidClick {
    
    ZHMineSetViewController *setVc = [[ZHMineSetViewController alloc]init];
    
    
    if ([self.delegate respondsToSelector:@selector(loginSettingViewController:)]) {
        [self.delegate loginSettingViewController:setVc];
    }
    
}

@end
